package com.wd.live.view.custom

import HttpUtils
import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.WindowManager
import android.widget.ImageView
import android.widget.TextView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ToastUtils
import com.wd.live.R
import com.wd.live.model.bean.LM_QuerylistBean
import com.wd.live.model.bean.LocalData
import com.wd.live.view.adapter.GiftRecyAdapter
import com.wd.live.view.adapter.LiveRecyAdapter1
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

//
//var callback:(LM_QuerylistBean)->Unit={}

class CustomDialog_gift_list(
    context: Context,
    var list: LocalData.QueryGiftBean,
    private val dispose: Dispose
) :
    Dialog(context) {
    var adapter: GiftRecyAdapter? = null
    var giftid: Int? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_custom_dialog_gift_list)
        initWindow()
        initView()
    }

    private fun initView() {
        val recy_gift = findViewById<RecyclerView>(R.id.recy_gift)
        val send_gift = findViewById<TextView>(R.id.send_gift)
        adapter = context?.let { it1 ->
            GiftRecyAdapter(context, list) {
                giftid = it.giftId
            }
        }
        list?.result?.let {
            recy_gift.layoutManager = GridLayoutManager(context, 3)
            recy_gift.adapter = adapter
        }
        send_gift.setOnClickListener {
            giftid?.let { it1 ->
                dispose.giveGift(it1)
            }
        }
    }

    private fun initWindow() {
        val window = window
        if (window != null) {
            window.setGravity(Gravity.BOTTOM)
            window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

            //获得window窗口的属性
            val lp = window.attributes
            lp.width = WindowManager.LayoutParams.MATCH_PARENT
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT
            window.attributes = lp
        }
    }
}